home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
msn
/
NSSBAdapter.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
6KB
|
163 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from logging import getLogger
log = getLogger('msn.nssb')
import msn
from msn import MSNTextMessage
from util import get, callsback
from util.Events import EventMixin
class NSSBAdapter(EventMixin):
_instances = []
events = EventMixin.events | set(('on_buddy_join', 'on_buddy_leave', 'on_buddy_timeout', 'on_conn_success', 'on_authenticate', 'disconnect', 'contact_alias', 'needs_auth', 'recv_error', 'recv_text_msg', 'send_text_msg', 'typing_info', 'recv_action', 'recv_p2p_msg', 'transport_error'))
def __init__(self, ns, to_invite = ()):
EventMixin.__init__(self)
self.ns = ns
self.principals = []
self.to_invite = to_invite
self._NSSBAdapter__chatbuddy = get(to_invite, 0, None)
def _closed(self):
return not (self.connected)
_closed = property(_closed)
def self_buddy(self):
return self.ns.self_buddy
self_buddy = property(self_buddy)
def invite(self, bname, callback = None):
self.buddy_join(bname)
callback.success()
invite = callsback(invite)
def buddy_join(self, bname):
if self._NSSBAdapter__chatbuddy is None:
self._NSSBAdapter__chatbuddy = bname
if bname not in self.principals:
self.principals.append(bname)
self.event('on_buddy_join', bname)
def send_text_message(self, message):
payload = message
netid = 32
msg = msn.Message('UUM', self._NSSBAdapter__chatbuddy, netid, 1, payload = str(payload))
self.ns.socket.send(msg, trid = True, callback = sentinel)
self.event('send_text_msg', payload)
def on_send_message(self, msg):
return NotImplemented
def leave(self):
if self in self._instances:
self._instances.remove(self)
self.event('disconnect')
def connect(self, callback = None):
log.info('NSSB.connect()')
self._instances.append(self)
self.event('on_conn_success', self)
log.info('NSSB.on_conn_success()')
for bname in self.to_invite:
self.buddy_join(bname)
self.event('on_authenticate')
log.info('NSSB.on_authenticate()')
callback.success()
connect = callsback(connect)
def connected(self):
return self.ns.connected()
def disconnect(self):
self.event('disconnect')
def close_transport(self):
pass
def on_conn_fail(self):
self.event('recv_error')
def authenticate(self, bname):
self.event('on_authenticate')
def send_typing_status(self, name, status):
payload = []
line = lambda k, v: '%s: %s' % (k, v)
add = payload.append
add(line('MIME-Version', '1.0'))
add(line('Content-Type', 'text/x-msmsgscontrol'))
add(line('TypingUser', name))
add('')
add('')
payload = '\r\n'.join(payload)
netid = 32
msg = msn.Message('UUM', self._NSSBAdapter__chatbuddy, netid, 2, payload = payload)
self.ns.socket.send(msg, trid = True, callback = sentinel)
def on_error(self, msg):
pass
def recv_msg(self, msg):
try:
print msg.type
getattr(self, 'recv_msg_%s' % msg.type, self.recv_msg_unknown)(msg)
except:
import traceback as traceback
traceback.print_exc()
print 'Exception handling MSG!'
print msg
def recv_msg_plain(self, msg):
(name, nick) = msg.args[:2]
msg = MSNTextMessage.from_net(msg.payload)
self.event('recv_text_msg', name, msg)
def recv_msg_control(self, msg):
name = msg.args[0]
self.event('typing_info', name, bool(msg.payload.get('TypingUser', False)))
def recv_msg_unknown(self, msg):
print "ohnoes don't know this message type:", type(msg), msg
def incoming(cls, msg):
name = msg.args[0]
for x in cls._instances:
if x._NSSBAdapter__chatbuddy == name:
break
continue
else:
x = cls(None)
x.buddy_join(name)
x.recv_msg(msg)
incoming = classmethod(incoming)